package org.androidpn.adapter;

import java.util.List;

import org.androidpn.R;
import org.androidpn.model.CHotTag;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TagGridViewAdapter extends BaseAdapter {
	Context context;
	private List<CHotTag> tags;

	private static int[] mColors = { 0xFFF87311, 0xFFF4A816, 0xFF60BC12, 0xFF0FC178, 0xFF1974BB, 0xFFA43C9A, 0xFFD91B5B,
			0xFF565656 };
	private static String[] mColorsString = { "#FFF87311", "#FFF4A816", "#FF60BC12", "#FF0FC178", "#FF1974BB",
			"#FFA43C9A", "#FFD91B5B", "#FF565656" };

	public void setTags(List<CHotTag> tags) {
		this.tags = tags;
	}

	public TagGridViewAdapter(Context context) {
		this.context = context;
	}

	@Override
	public int getCount() {
		return tags.size();
	}

	@Override
	public Object getItem(int arg0) {
		return tags.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View arg1, ViewGroup arg2) {
		ViewHodler viewHodler;
		if (arg1 == null) {
			arg1 = View.inflate(context, R.layout.tag_gv_item, null);
			viewHodler = new ViewHodler();
			viewHodler.tvTag = (TextView) arg1.findViewById(R.id.tv_tag);
			arg1.setTag(viewHodler);
		} else {
			viewHodler = (ViewHodler) arg1.getTag();
		}
		viewHodler.tvTag.setBackgroundColor(Color.parseColor(mColorsString[position % 8]));
		viewHodler.tvTag.setText(tags.get(position).getTag());
		return arg1;
	}

	class ViewHodler {
		TextView tvTag;
	}
}
